package com.qining618.cms.cms.mapper;

import com.qining618.cms.cms.domain.ContentCount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qining618.cms.cms.enums.ContentOperateEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * CMS内容计数表 Mapper 接口
 * </p>
 *
 * @author qining
 * @date 2019-09-17
 */
@Mapper
@Repository
public interface ContentCountMapper extends BaseMapper<ContentCount> {

    /**
     * 增加内容评论数量
     * @param contentId 内容id
     * @param num 数量
     * @return int 操作数量
     */
    @Update("update c_content_count set comments = comments + #{num}, comments_month = comments_month + #{num}," +
            " comments_week = comments_week + #{num}, comments_day = comments_day + #{num}" +
            " where content_id = #{contentId}")
    int incCommentCount(@Param("contentId") Long contentId, @Param("num") Integer num);

    /**
     * 获取指定内容的顶数
     * @param contentId 内容id
     * @return int 操作数量
     */
    @Select("select ups from c_content_count where content_id = #{contentId}")
    int getContentUpsByContentId(@Param("contentId") Long contentId);

    /**
     * 增加内容顶数
     * @param contentId 内容id
     * @param num 数量
     * @return int 操作数量
     */
    @Update("update c_content_count set ups = ups + #{num}, ups_month = ups_month + #{num}," +
            " ups_week = ups_week + #{num}, ups_day = ups_day + #{num} where content_id = #{contentId}")
    int incContentUp(@Param("contentId") Long contentId, @Param("num") Integer num);

    /**
     * 获取指定内容的踩数
     * @param contentId 内容id
     * @return int 操作数量
     */
    @Select("select downs from c_content_count where content_id = #{contentId}")
    int getContentDownsByContentId(@Param("contentId") Long contentId);

    /**
     * 增加内容踩数
     * @param contentId 内容id
     * @param num 数量
     * @return int 操作数量
     */
    @Update("update c_content_count set downs = downs + #{num} where content_id = #{contentId}")
    int incContentDown(@Param("contentId") Long contentId, @Param("num") Integer num);

}
